DeferredView holds a View and performs deferred actions upon it

part of wslib

This class is intended to give an alternative solution to the problem that causes GUI actions to fail when called from MIDIResponder functions and Routines etc.. Usually when getting or setting a value of a View from inside such a function one has to cal Function:defer, which makes the call run from AppClock instead. The downside of that is that if the View has an action responding to such a change, the action also gets evaluated by AppClock. This can sometimes result in slow response. This class separates the action and values from the actual View, and thus enables direct control from Routines and MIDIResponder functions.

The easiest way to use it is the SCView:defer shortcut, which points to DeferredView. I'll explain the use of this class with the following set of examples:

(

// first we setup a Window with a slider

w = Window().front;

w.addFlowLayout;

z = Slider( w, 120@20 );

z.action = { |vw| vw.value.postln; }; // moving the slider shows the value in the post window

)

Now, if we would want to make this slider move we would have to do the following:

(

{

10.do({ |i|

{ z.valueAction = i/9; }.defer;

0.1.wait;

});

}.fork;

)

With DeferredView we can do it much simpler

(

z = z.defer; // convert the View to a DeferredView

{

10.do({ |i|

z.valueAction = i/9;

0.1.wait;

});

}.fork;

)